package com.umakr.ax.app.service;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.umakr.ax.common.mapper.RadioStationShowMapper;
import com.umakr.ax.common.model.*;
import com.umakr.ax.common.service.*;
import com.umakr.ax.common.vo.RadioStationShowVO;
import com.umakr.ax.core.base.BaseService;
import com.umakr.ax.oss.service.StsServiceSample;
import com.umakr.ax.utils.FormatPhotoUrlUtil;
import com.umakr.ax.utils.WebUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.Date;
import java.util.Map;

@Service
public class RadioStationShowWebService  extends BaseService<RadioStationShowMapper, RadioStationShow> {

    @Autowired
    RadioStationShowService radioStationShowService;
    @Autowired
    ShowFabulousService showFabulousService;
    @Autowired
    FavoriteService favoriteService;
    @Autowired
    ShowDiscussService showDiscussService;
    @Autowired
    LableService lableService;
    @Autowired
    CodeService codeService;
    @Autowired
    ShowLableService showLableService;
    @Autowired
    RadioStationService radioStationService;
    @Autowired
    StsServiceSample stsServiceSample;

    @Autowired
    Environment env;

    public Object saveRadioStationShow( RadioStationShow show ) {
       return radioStationShowService.saveRadioStationShow(show);
    }

    public Object delRadioStationShow( Long showId ){
        return radioStationShowService.delRadioStationShow(showId);
    }

    public Object listRadioStationShow( Long rsId ) {
        String aliUrl = env.getProperty("oss.img.path");
        Page<RadioStationShowVO> radioStationShowVOPage = baseMapper.listRadioStationShow(rsId);

        if(radioStationShowVOPage != null){
            for (RadioStationShowVO rsShowVO : radioStationShowVOPage.getRecords()) {
                rsShowVO.setRsLogo(rsShowVO.getRsLogo() ==null ? "":aliUrl+rsShowVO.getRsLogo());

                rsShowVO.setShowAttachment(FormatPhotoUrlUtil.formatJson(aliUrl,rsShowVO.getShowAttachment()));

                Long showId = rsShowVO.getId();

                //处理秀收藏条数
                EntityWrapper<Favorite> favoriteWrapper = new EntityWrapper<>();
                favoriteWrapper.eq("universal_id", showId);
                favoriteWrapper.eq("fav_type", 0);
                favoriteWrapper.eq("del_staus", 0);
                Integer favoriteCount = favoriteService.selectCount(favoriteWrapper);
                rsShowVO.setFavoriteCount(favoriteCount);

                //重新给评论数量赋值：审核通过+未审核数量
                EntityWrapper<ShowDiscuss> showDiscussWrapper = new EntityWrapper<>();
                showDiscussWrapper.eq("show_id", showId);
                showDiscussWrapper.eq("del_status", 0);
                Integer showDiscussCount = showDiscussService.selectCount(showDiscussWrapper);
                rsShowVO.setCommentCount(showDiscussCount);
            }
        }
        return radioStationShowVOPage;
    }
}
